package main.java.chessfootball.rules.checker;

import main.java.chessfootball.model.game.Player;

/**
 * User: Igor
 * Date: 28.07.2011
 * Time: 22:12:51
 */
public class OffsideChecker extends AbstractMoveChecker
{
	@Override
	public boolean valid()
	{
		if (game.getRule().getGame().isOffside())
		{
			if (move.getLength() > 1)
			{

			}
		}
		return true;
	}

	private int lineDef()
	{
		Player lastDef = null;
		Player secondLastDef = null;
		for (Player player : game.getField().getTeam(move.getSide().getInvert()).getPlayers())
		{
			if ((lastDef == null) || (player.getCell().getX() < lastDef.getCell().getX()))
			{
				lastDef = player;
			}
		}
		for (Player player : game.getField().getTeam(move.getSide().getInvert()).getPlayers())
		{
			if (!(player.equals(lastDef)) && ((secondLastDef == null) || (player.getCell().getX() < secondLastDef.getCell().getX())))
			{
				secondLastDef = player;
			}
		}
		assert secondLastDef != null;
		return secondLastDef.getCell().getX();
	}
}
